package com.cn.client.controller;



import com.cn.api.FrontFeignClient;
import com.cn.client.vo.couponVO.AdvertisementVO;
import com.cn.client.vo.couponVO.FrontCouponVO;
import com.cn.common.result.Result;
import com.cn.dto.CouponDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@Api(tags = "客户端操作")
@RestController
@RequestMapping("/front/coupon")
@Slf4j
public class FrontCouponController {

    @Autowired
    private FrontFeignClient frontFeignClient;

    @ApiOperation(value = "优惠券广告")
    @PostMapping("/advertisement")
    public Result<AdvertisementVO> advertisement(int coupon_id){
        CouponDTO couponDTO = new CouponDTO();
        AdvertisementVO advertisementVO = new AdvertisementVO();
        couponDTO = frontFeignClient.advertisement(coupon_id);
        advertisementVO.setName(couponDTO.getName());
        advertisementVO.setImg(couponDTO.getImg());
        advertisementVO.setCoupon_amount(couponDTO.getCoupon_amount());
        advertisementVO.setExplain(couponDTO.getExplain());
        return Result.success(advertisementVO);
    }

    @ApiOperation(value = "查询所有优惠券")
    @PostMapping("/findAll")
    public Result<List<FrontCouponVO>> findAll(FrontCouponVO frontCouponVO){
        CouponDTO couponDTO = new CouponDTO();
        List<FrontCouponVO> list = new ArrayList<>();
        List<CouponDTO> list1 = frontFeignClient.findAll(couponDTO);
        for (CouponDTO couponDTO1 : list1){
            FrontCouponVO frontCouponVO1 = new FrontCouponVO();
            frontCouponVO1.setCoupon_amount(couponDTO1.getCoupon_amount());
            frontCouponVO1.setEffective_time(couponDTO1.getEffective_time());
            frontCouponVO1.setState(couponDTO1.getState());
            frontCouponVO1.setType(couponDTO1.getType());
            frontCouponVO1.setName(couponDTO1.getName());
            list.add(frontCouponVO1);
        }

        return Result.success(list);
    }

    @ApiOperation(value = "根据状态查询优惠券")
    @PostMapping("/findByStatus")
    public Result findByStatus(int status){
        return null;
    }

    @ApiOperation(value = "去领取")
    @PostMapping("/getCoupon")
    public Result getCoupon(){
        return null;
    }

    @ApiOperation(value = "优惠券领取")
    @PostMapping("/receive")
    public Result receive(int id){
        return null;
    }

    @ApiOperation(value = "去使用")
    @PostMapping("/usedCoupon")
    public Result usedCoupon(int id){
        return null;
    }

}
